#ifndef BILATERALFILTER_H
#define BILATERALFILTER_H

#include "../data/reg3dvolumedata.h"

namespace PBVP {
	/// Bilateral filter for regular 3D data 
	class BilateralFilter
	{
	public:
		/// Constructor
		BilateralFilter();
		
		/// Destructor
		~BilateralFilter();

		///
		Reg3DVolumeData* filter(Reg3DVolumeData* pData);

		/// 
		/** 
		 * @note This function will overwrite the incoming data
		 */
		void filterIterative(Reg3DVolumeData* &pData, unsigned int n = 1);

		///
		int filterRadius() const {
			return m_FilterRadius;
		}

		///
		void setFilterRadius(int r) {
			m_FilterRadius = r;
		}

	private:
		/// Filtering coefficient in space 
		double m_SigmaSpat;
		/// Filtering coefficient in function space
		double m_SigmaFunc;
		/// Spatial radius of the filter
		int m_FilterRadius;

		double *m_SpatMask;
		
		/// Compute the filtered value at a vertex
		float filterVertex(Reg3DVolumeData* pData, unsigned int dim[3], 
			int vx, int vy, int vz);

		/// Compute spatial mask of a regular 3D data
		void calcSpatialMask(Reg3DVolumeData *pData);

		/// 
		int maskId(int i, int j, int k);
	};

}
#endif // BILATERALFILTER_H
